<template>
  <div>
    <el-drawer :visible.sync="drawer" direction="rtl" size="50%" :with-header="false" :destroy-on-close="true">
      <div class="drawer_box">
        <div class="drawer_t">
          <div class="drawer_t_l">
            <img class="drawer_t_l_img" src="/static/skin/herodoo/main/platform/home/img/quanyishaixuan.png" alt="" />
            {{ isEdit ? "查看" : "创作" }}精品权益
          </div>
          <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt="" @click="close" />
        </div>
        <div class="created_content">
          <div class="created_content_list">
            <!-- 基础信息 -->
            <div class="block_box">
              <div class="title">基础信息</div>
              <div class="list_box">
                <div class="left">所属项目:</div>
                <div class="right" :class="inputValue.ProjectID == '' ? 'right_boder' : ''">
                  <el-select :disabled="isEdit" v-model="inputValue.ProjectID" placeholder="请选择所属项目" filterable
                    clearable>
                    <el-option v-for="item in sourceList" :key="item.ID" :label="item.Name"
                      :value="item.ID"></el-option>
                  </el-select>
                </div>
              </div>
              <div class="list_box">
                <div class="left">权益标题:</div>
                <div class="right" :class="inputValue.title ? '' : 'right_boder'">
                  <el-input v-model="inputValue.title" placeholder="请输入权益标题" :disabled="isEdit"></el-input>
                </div>
              </div>
              <div class="list_box">
                <div class="left">公司名称:</div>
                <div class="right" :class="compnySelect.value == '' ? 'right_boder' : ''">
                  <el-select :disabled="octopus.passport.authorization.company != 1 || isEdit
                    " v-model="compnySelect.value" placeholder="请选择公司名称" @change="changeCompny()" filterable clearable>
                    <el-option v-for="item in compnySelect.options" :key="item.ID" :label="item.Name" :value="item.ID">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="list_box">
                <div class="left">产品类型:</div>
                <div class="right" :class="typeSelect.value == '' ? 'right_boder' : ''">
                  <el-select v-model="typeSelect.value" placeholder="请选择产品类型" :no-data-text="typeSelect.options.length == 0 && compnySelect.value
                    ? '该公司暂无产品'
                    : '请先选择公司名称'
                    " @change="changeType()" filterable clearable :disabled="isEdit">
                    <el-option v-for="item in typeSelect.options" :key="item.ID" :label="item.Name" :value="item.ID">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="list_box">
                <div class="left">产品名称:</div>
                <div class="right" :class="productsSelect.value == '' ? 'right_boder' : ''">
                  <el-select v-model="productsSelect.value" placeholder="请选择产品名称" :no-data-text="productsSelect.options.length == 0 && typeSelect.value
                    ? '该产品类型暂无产品'
                    : '请先选择产品类型'
                    " @change="changeName()" filterable clearable :disabled="isEdit">
                    <el-option v-for="item in productsSelect.options" :key="item.ID" :label="item.Name"
                      :value="item.ID">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="list_box">
                <div class="left">合同编号:</div>
                <div class="right" :class="contractSelect.value == '' ? 'right_boder' : ''">
                  <el-select v-model="contractSelect.value" placeholder="请选择合同编号" no-data-text="请先选择产品名称"
                    @change="changeContract" :disabled="isEdit">
                    <el-option v-for="item in contractSelect.options" :key="item.ID" :label="item.Code"
                      :value="item.ID">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="list_box" v-if="lableList.length" style="margin-bottom: 0;">
                <div class="left">已选权益标签：</div>
                <div class="right">
                  <div class="exhibition">
                    <!-- <div class="exhibition_title">所选内容:</div> -->
                    <div class="exhibition_content">
                      <div class="exhibition_content_list" v-for="item in lableList" :key="item">
                        <div class="content_list_name">{{ item }}</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="list_box" v-if="!isEdit">
                <div class="left">权益标签:</div>
                <div class="right">
                  <div class="add_content" @click="ShowLabelDialog()">
                    <i class="el-icon-plus"></i>
                    <span>点击添加标签</span>
                  </div>
                </div>
              </div>
              <div class="list_box" v-if="compnyList.length" style="margin-bottom: 0;">
                <div class="left">已选采购公司权限：</div>
                <div class="right">
                  <div class="exhibition">
                    <!-- <div class="exhibition_title">所选内容:</div> -->
                    <div class="exhibition_content">
                      <div class="exhibition_content_list" v-for="item in compnyList" :key="item">
                        <div class="content_list_name">{{ item }}</div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="list_box" v-if="!isEdit">
                <div class="left">采购公司权限设置:</div>
                <div class="right">
                  <div class="add_content" @click="ShowCompngDialog()">
                    <i class="el-icon-plus"></i>
                    <span>点击添加权限</span>
                  </div>
                </div>
              </div>
              <div class="list_box">
                <div class="left">使用期限:</div>
                <div class="right" :class="time ? '' : 'right_boder'">
                  <dataPicker @timeList="timeDataList" :isEdit="isEdit" :time="time" :key="time"></dataPicker>
                </div>
              </div>
              <!-- <div class="list_box" v-for="(item, ind) in dataList" v-if="dataList.length" :key="item">
                <div class="left"></div>
                <div class="right" style="display: flex;align-items: baseline;">
                  <dataPicker @timeList="timeDataList"></dataPicker>
                  <i class="el-icon-delete" @click="delteData(ind)"></i>
                </div>
              </div> -->
              <!-- <div class="list_box">
                <div class="left"></div>
                <div class="right">
                  <div class="add_content" @click="addData()">
                    <i class="el-icon-plus"></i>
                    <span>点击添加使用期限</span>
                  </div>
                </div>
              </div> -->
              <div class="list_box">
                <div class="left">库存数量(份):</div>
                <div class="right" :class="inputValue.inventory ? '' : 'right_boder'">
                  <el-input @input="e => {
                    this.inputValue.inventory = Number(
                      e.replace(/[^\d]/g, '')
                    );
                  }
                    " class="numberInput" v-model.number="inputValue.inventory" placeholder="请输入库存数量" type="text"
                    :disabled="isEdit"></el-input>
                </div>
              </div>
              <div class="list_box">
                <div class="left">起购数量(份):</div>
                <div class="right" :class="inputValue.MPnum ? '' : 'right_boder'">
                  <el-input @input="e => {
                    this.inputValue.MPnum = Number(e.replace(/[^\d]/g, ''));
                  }
                    " class="numberInput" v-model.number="inputValue.MPnum" placeholder="请输入起购数量" type="text"
                    :disabled="isEdit"></el-input>
                </div>
              </div>
              <div class="list_box">
                <div class="left">市场价格(元):</div>
                <div class="right">
                  <el-input @input="e => {
                    this.inputValue.marketPrice = e.replace(/[^\d.]/g, '');
                  }
                    " class="numberInput" v-model.number="inputValue.marketPrice" placeholder="请输入市场价格" type="text"
                    :disabled="isEdit"></el-input>
                  <!-- {{ inputValue.marketPrice ? inputValue.marketPrice : '--' }}元 -->
                </div>
              </div>
              <div class="list_box">
                <div class="left">平台价格(元):</div>
                <div class="right">
                  <el-input @input="e => {
                    this.inputValue.platformPrice = e.replace(
                      /[^\d.]/g,
                      ''
                    );
                  }
                    " class="numberInput" v-model.number="inputValue.platformPrice" placeholder="请输入平台价格" type="text"
                    :disabled="isEdit"></el-input>
                  <!-- {{ inputValue.platformPrice ? inputValue.platformPrice : '---' }}元 -->
                </div>
              </div>
              <div class="list_box">
                <div class="left">权益平台服务费(%):</div>
                <div class="right" :class="inputValue.platformServiceCharge ? '' : 'right_boder'">
                  {{
                    inputValue.platformServiceCharge >= 0
                      ? inputValue.platformServiceCharge * 100
                      : "--"
                  }}
                  <!-- <el-input v-model="inputValue.platformServiceCharge" placeholder="请输入权益平台服务费"></el-input> -->
                  <!-- <el-input-number
                    v-model="inputValue.platformServiceCharge"
                    size="mini"
                    :min="0"
                    :max="100"
                    placeholder="请输入权益平台服务费"
                    :controls="false"
                    :disabled="true"
                  ></el-input-number> -->
                  <!-- {{ inputValue.platformServiceCharge ? inputValue.platformServiceCharge : '--' }}% -->
                </div>
              </div>
              <div class="list_box">
                <div class="left">小程序服务费(%):</div>
                <div class="right" :class="inputValue.APPServiceCharge ? '' : 'right_boder'">
                  <!-- <el-input v-model="inputValue.APPServiceCharge" placeholder="请输入小程序服务费"></el-input> -->
                  <!-- {{ inputValue.APPServiceCharge ? inputValue.APPServiceCharge : '--' }}% -->
                  {{
                    inputValue.APPServiceCharge >= 0
                      ? inputValue.APPServiceCharge * 100
                      : "--"
                  }}
                  <!-- <el-input-number
                    v-model="inputValue.APPServiceCharge"
                    size="mini"
                    :min="0"
                    :max="100"
                    placeholder="请输入权益平台服务费"
                    :controls="false"
                    :disabled="true"
                  ></el-input-number> -->
                </div>
              </div>
              <div class="list_box">
                <div class="left">让利积分:</div>
                <div class="right" :class="inputValue.Integral == 0 ||
                  inputValue.Integral / (inputValue.platformPrice * 10) >= 0.1
                  ? 'right_boder'
                  : ''
                  ">
                  <el-input @input="e => {
                    this.inputValue.Integral = Number(
                      e.replace(/[^\d]/g, '')
                    );
                  }
                    " class="numberInput" v-model.number="inputValue.Integral" type="text"
                    placeholder="请输入让利积分(1积分=1角)" :disabled="isEdit"></el-input>
                  <div style="color: red;font-size: 1.2rem;" v-if="
                    inputValue.platformPrice *
                    (1 - inputValue.APPServiceCharge / 100) <
                    inputValue.Integral
                  ">
                    您当前输入的让利积分大于售价的10%，请确认积分设置是否过高
                  </div>
                  <div v-else style="color: #CFCCCB;font-size: 1.2rem;">
                    积分留在资金池内,供用户再次在您的私域小程序进行消费时使用抵扣
                  </div>
                </div>
              </div>
              <div class="list_box">
                <div class="left">平台结算价格(元)</div>
                <div class="right">¥{{ isplatPrice }}</div>
              </div>
              <div class="list_box">
                <div class="left">小程序结算价格(元)</div>
                <div class="right">¥{{ isappPrice }}</div>
              </div>
              <div class="list_box" style="align-items: center;">
                <div class="left" style="padding-right: .5rem;">
                  是否允许在其他国企民企平台进行售卖
                </div>
                <div class="right">
                  <el-radio v-model="channel" label="1" :disabled="isEdit">是</el-radio>
                  <el-radio v-model="channel" label="0" :disabled="isEdit">否</el-radio>
                </div>
              </div>
              <div class="list_box">
                <div class="left">使用地址:</div>
                <div class="right" :class="inputValue.location ? '' : 'right_boder'">
                  <el-input v-model="inputValue.location" placeholder="请输入权益使用地址" :disabled="isEdit"></el-input>
                </div>
              </div>
              <div class="list_box">
                <div class="left">使用人数:</div>
                <div class="right" :class="inputValue.usersCount ? '' : 'right_boder'">
                  <el-input @input="e => {
                    this.inputValue.usersCount = Number(
                      e.replace(/[^\d]/g, '')
                    );
                  }
                    " class="numberInput" v-model.number="inputValue.usersCount" type="text" placeholder="请输入使用人数"
                    :disabled="isEdit"></el-input>
                </div>
              </div>
              <div class="list_box">
                <div class="left">购买是否需要提供身份信息：</div>
                <div class="right">
                  <el-radio v-model="authRadio" label="1" :disabled="isEdit">是</el-radio>
                  <el-radio v-model="authRadio" label="0" :disabled="isEdit">否</el-radio>
                </div>
              </div>
              <div class="list_box">
                <div class="left">是否需要商家二次确认</div>
                <div class="right">
                  <el-radio v-model="refundRadio" label="1" :disabled="isEdit">是</el-radio>
                  <el-radio v-model="refundRadio" label="0" :disabled="isEdit">否</el-radio>
                </div>
              </div>
              <div class="list_box">
                <div class="left">是否允许退款</div>
                <div class="right">
                  <el-radio v-model="radio" label="1" :disabled="isEdit">是</el-radio>
                  <el-radio v-model="radio" label="0" :disabled="isEdit">否</el-radio>
                </div>
              </div>
              <div class="list_box" v-show="radio == '1'">
                <div class="left">退款规则</div>
                <div class="right">
                  <el-radio v-model="refundType" label="1" :disabled="isEdit">无条件退款</el-radio>
                  <el-radio v-model="refundType" label="0" :disabled="isEdit">申请退款日距权益使用截止日期前</el-radio>
                  <block v-if="refundType == 0">
                    <div style="margin: 1rem 0;" v-for="(item, index) in refundTypeArr" :key="index">
                      <el-input @input="e => {
                        item.skyNumber = Number(e.replace(/[^\d]/g, ''));
                      }
                        " class="small numberInput" style="margin-right: 1rem;" v-model="item.skyNumber"
                        placeholder="小时" type="text" :disabled="isEdit"></el-input>小时 , 支持退款
                      <el-input @input="e => {
                        item.proportion = Number(e.replace(/[^\d]/g, ''));
                      }
                        " class="small numberInput" style="margin: 0 1rem;" v-model="item.proportion"
                        placeholder="退款百分比" type="text" :disabled="isEdit"></el-input>%
                      <i class="el-icon-delete" v-if="refundTypeArr.length > 1" @click="deleteRefund(index)"></i>
                    </div>
                    <div class="add_content" @click="addRule()" v-if="!isEdit">
                      <i class="el-icon-plus"></i>
                      <span>点击添加规则</span>
                    </div>
                  </block>
                </div>
              </div>
              <div class="list_box" v-if="radio == 1">
                <div class="left">退款是否需要审核：</div>
                <div class="right">
                  <el-radio v-model="auditRadio" label="1" :disabled="isEdit">是</el-radio>
                  <el-radio v-model="auditRadio" label="0" :disabled="isEdit">否</el-radio>
                </div>
              </div>
              <!-- 海报 -->
              <!-- <div class="list_box">
                <div class="left">海报：</div>
                <div class="right">
                  海报仅可上传1张图片，图片不超过512KB，仅支持jpg、png格式，建议比例1：1
                </div>
              </div>
              <div class="list_box">
                <div class="left"></div>
                <div class="right">
                  <update ref="update" :num="1" :octopus="octopus" @imgList="getPosterList" :isEdit="isEdit"
                    :list="posterImg"></update>
                </div>
              </div> -->
              <!-- 主图 -->
              <div class="list_box">
                <div class="left">权益主图：</div>
                <div class="right">
                  主图仅可上传1张图片，图片不超过512KB，仅支持jpg、png格式，建议比例1：1
                </div>
              </div>
              <div class="list_box">
                <div class="left"></div>
                <div class="right">
                  <update ref="update" :num="1" :octopus="octopus" :list="masterImg" @imgList="getMasterList"
                    :isEdit="isEdit"></update>
                </div>
              </div>
              <!-- 附图 -->
              <div class="list_box">
                <div class="left">权益附图：</div>
                <div class="right">
                  附图可上传7张图片，单张图片不超过512KB，仅支持jpg、png格式，建议比例1：1
                </div>
              </div>
              <div class="list_box">
                <div class="left"></div>
                <div class="right">
                  <update ref="updateFigures" :multiple="true" @imgList="getFiguresList" :list="figuresList" :num="7"
                    :octopus="octopus" :isEdit="isEdit">
                  </update>
                </div>
              </div>
            </div>
            <!-- 权益内容 -->
            <div class="block_box">
              <div class="title">权益内容</div>
              <div class="list_box" style="display: block;">
                <div class="left">权益详情:</div>
                <div class="right" style="width: 100%;line-height: 1rem;">
                  <!-- <quill ref="quill" :octopus="octopus" @quillContent="getQuillContent" :desc="deltedContent" :isEdit="isEdit"></quill> -->
                  <quill ref="quill" :octopus="octopus" :desc="inputValue.deltedContent" @quillContent="getQuillContent"
                    :isEdit="type" refName="quill3" refInput="quill3i"></quill>
                </div>
              </div>
              <div class="list_box" style="display: block;">
                <div class="left">使用规则:</div>
                <div class="right" style="width: 100%;line-height: 1rem;">
                  <quill ref="quillRules" :octopus="octopus" @quillContent="getQuillRulesContent"
                    :desc="inputValue.rulesContent" :isEdit="type" refName="quill4" refInput="quill4i"></quill>
                </div>
              </div>
            </div>
            <div class="button_list" v-if="type != 'look'">
              <button style="background-color: #1E1B19;" @click="save(1, 1)">
                存入草稿
              </button>
              <button @click="save(2)">发布</button>
            </div>
          </div>
        </div>
      </div>
    </el-drawer>
    <LabelDialog ref="LabelDialog" @lableList="getLableList" :is_addNew="false"></LabelDialog>
    <CompnyDialog ref="CompnyDialog" @compnyList="getCompnyList"></CompnyDialog>
  </div>
</template>
<script>
import update from "@/components/Components/imgUpdate.vue";
import quill from "@/components/Components/quillEditor.vue";
import dataPicker from "../Components/dataPicker.vue";
import LabelDialog from "./labelDialog.vue";
import CompnyDialog from "./compnyDialog.vue";
export default {
  name: "screen_Rights",
  components: {
    update,
    quill,
    dataPicker,
    LabelDialog,
    CompnyDialog
  },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    isplatPrice() {
      //权益平台结算价格=自有权益的平台价格-（自有权益的平台价格*自有权益权益平台的服务费）
      let platPrice = 0;
      platPrice =
        this.inputValue.platformPrice -
        this.inputValue.platformPrice * this.inputValue.platformServiceCharge;
      platPrice ? platPrice : (platPrice = 0);
      return Math.floor(platPrice * 100) / 100;
    },
    isappPrice() {
      //小程序结算价格=自有权益的平台价格-（自有权益的平台价格*自有权益小程序的服务费）-（自有权益的让利积分/10）
      let appPrice = 0;
      appPrice =
        this.inputValue.platformPrice -
        this.inputValue.platformPrice *
        (this.inputValue.APPServiceCharge +
          this.inputValue.platformServiceCharge) -
        this.inputValue.Integral / 10;
      appPrice ? appPrice : (appPrice = 0);
      return Math.floor(appPrice * 100) / 100;
    }
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      sourceList: [],
      // 产品类型
      typeSelect: {
        options: [],
        value: ""
      },
      // 合同编号
      contractSelect: {
        options: [],
        value: ""
      },
      // 公司名称
      compnySelect: {
        options: [],
        value: ""
      },
      // 产品名称
      productsSelect: {
        options: [],
        value: ""
      },
      radio: "1", //是否退款
      auditRadio: "1", //退款是否需要审核
      authRadio: "1", // 购买是否需要实名
      refundRadio: "1", //是否需要商家二次确认
      channel: "1", //是否允许在其他国企民企平台进行售卖
      refundType: "1", //退款规则
      refundTypeArr: [
        {
          id: 1,
          skyNumber: "",
          proportion: "",
          reduce: ""
        }
      ],
      inputValue: {
        ProjectID: '',//项目ID
        id: "",
        title: "", //权益标题
        inventory: "", //库存数量
        MPnum: "", //起购数量
        marketPrice: "", //市场价格
        platformPrice: "", //平台价格
        platformServiceCharge: "", //权益平台服务费
        APPServiceCharge: "", //小程序服务费
        Integral: 0, //让利积分
        location: "", //权益地址
        usersCount: 1, //使用人数
        time: "", //使用期限
        compnySelect: "", //公司名称
        typeSelect: "", //产品类型
        productsSelect: "", //产品名称
        contractSelect: "", //合同编号
        lableListID: "", //权益标签
        radio: "1", //退款规则
        posterImg: "", //海报
        masterImg: "", //主图
        figuresList: "", //附图
        deltedContent: "", //权益详情
        rulesContent: "" //使用规则
      },
      rulesArr: [], //
      lableList: [],
      lableListID: [],
      compnyList: [],
      compnyListID: [],
      dataList: [],
      timeList: [],
      dataInd: 0,
      title: "添加权益",
      posterImg: [], // 海报
      masterImg: [], //主图
      figuresList: [], //附图
      time: "", //使用期限
      deltedContent: "", //权益详情
      rulesContent: "", //使用规则
      runles: {
        //字段规则，验证使用
        ProjectID: { required: true, message: "请选择所属项目！" },
        title: { required: true, message: "请输入权益标题！" },
        compnySelect: { required: true, message: "请输入公司名称！" },
        typeSelect: { required: true, message: "请选择产品类型！" },
        productsSelect: { required: true, message: "请选择产品名称！" },
        contractSelect: { required: true, message: "请选择合同编号！" },
        lableListID: { required: true, message: "请添加权益标签！" },
        time: { required: true, message: "请选择使用期限！" },
        inventory: { required: true, message: "库存数量必须大于0！" },
        MPnum: {
          required: true,
          message: "起购数量不能大于库存数量并且不为0！",
          reg: () => {
            return this.inputValue.MPnum <= 0 ||
              this.inputValue.MPnum > this.inputValue.inventory
              ? false
              : true;
          }
        },
        marketPrice: { required: true, message: "市场价格必须大于0！" },
        platformPrice: { required: true, message: "平台价格必须大于0！" },
        Integral: { required: false, message: "让利积分不能小于0！" },
        location: { required: true, message: "请输入使用地址！" },
        usersCount: {
          required: true,
          message: "使用人数必须大于0！",
          reg: () => {
            return this.inputValue.usersCount <= 0 ? false : true;
          }
        },
        radio: {
          required: true,
          message: "请输入正确的退款条件！",
          reg: () => {
            let status = false;
            if (this.inputValue.radio == 1 && this.refundType == 0) {
              status =
                this.refundTypeArr.filter(
                  x =>
                    x.skyNumber <= 0 ||
                    x.skyNumber == "" ||
                    x.proportion <= 0 ||
                    x.proportion == ""
                ).length != 0
                  ? false
                  : true;
            } else {
              status = true;
            }
            return status;
          }
        },
        imgList: { required: true, message: "请上传权益主图！" },
        figuresList: { required: true, message: "请上传至少一张权益附图！" },

        deltedContent: { required: true, message: "请输入权益详情！" },
        rulesContent: { required: true, message: "请输入使用规则！" }
      },
      type: "CREATE", //是新建还是更新
      platPrice: 0, //平台结算价格
      appPrice: 0, //小程序结算价格
      detailID: "",
      is_charge: false,//是否需要切换价格
      title: '',
    };
  },
  mounted() { },
  created() {
    this.api_1415();
    this.init();

  },
  watch: {
    "inputValue.Integral"(e) {
      if (e == 0) {
        this.inputValue.Integral = 0;
      }
    }
  },
  methods: {
    save(Status, flag = false) {
      this.inputValue.radio = this.radio;

      if (!this.octopus.tools.verify(this.inputValue, this.runles)) {
        return;
      }
      let min =
        this.inputValue.platformPrice *
        (1 - this.inputValue.APPServiceCharge / 100);
      if (this.inputValue.Integral / 10 > min) {
        this.$message({
          type: "warning",
          message: `让利积分不能大于${min * 10}`
        });
        return;
      }
      let text = Status == 1 ? "确认保存到草稿库吗?" : "确定发布该权益吗？";
      this.$confirm(text, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.addList(Status, flag);
        })
        .catch(() => {
          console.log("取消了");
        });
    },
    // 新增权益
    addList(Status, flag = false) {
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 748,
          type: this.type,
          value: this.type == "CREATE" ? "" : this.inputValue.ID,
          cellData: [
            { name: "ProjectID", defaultValue: this.inputValue.ProjectID },	// 项目ID
            { name: "Address", defaultValue: this.inputValue.location }, // 使用地址
            {
              name: "CompanyID",
              defaultValue:
                o.octopus.passport.authorization.company == 1
                  ? o.compnySelect.value
                  : o.compnySelect.options[0].ID
            }, // 公司ID
            { name: "ProductFlagList", defaultValue: this.inputValue.typeSelect }, // 产品类型
            { name: "ContractID", defaultValue: this.contractSelect.value }, // 合同编号
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 创建时间
            { name: "CreateUserID", defaultValue: this.octopus.passport.id }, // 创建人
            { name: "Description", defaultValue: this.deltedContent }, // 权益内容
            { name: "EffectiveTime", defaultValue: this.time[0] }, // 生效日期
            { name: "EquityList", defaultValue: "" }, // 外部权益包列表  字符串(逗号分开)
            { name: "ExpireTime", defaultValue: this.time[1] }, // 过期时间
            { name: "FlagList", defaultValue: this.lableListID }, // 权益标签
            { name: "Integral", defaultValue: this.inputValue.Integral }, // 让利积分
            { name: "IsOpenSale", defaultValue: this.channel }, // 是否允许在其他国企平台售卖(1.允许,0.不允许)
            { name: "IsRefund", defaultValue: this.inputValue.radio }, // 是否允许退款
            {
              name: "MainPicturePath",
              defaultValue: JSON.stringify(this.masterImg)
            }, // 主图
            { name: "MinimumQuantity", defaultValue: this.inputValue.MPnum }, // 起售数量
            { name: "Name", defaultValue: this.inputValue.title }, // 权益名称（标题）
            { name: "ProductID", defaultValue: this.productsSelect.value }, // ProductID
            // { name: "PosterPath", defaultValue: this.inputValue.posterImg },// 海报
            {
              name: "SecondaryPicturePath",
              defaultValue: JSON.stringify(this.figuresList)
            }, // 副图
            {
              name: "Status",
              defaultValue:
                Status == 1
                  ? "1"
                  : this.octopus.passport.authorization.company == 1
                    ? 5
                    : 2
            }, // 权益状态（保存未提交（草稿箱）、已提交/待审核、审核通过、审核未通过、未启用，启用、已售完、到期）
            { name: "TransferRuleID", defaultValue: this.compnyListID }, // 采购公司限制
            // { name: "TypeID" , defaultValue: this.typeSelect.value},	// 权益类型(单个类型、多个类型)
            { name: "TypeID", defaultValue: 1 }, // 权益类型(单个类型、多个类型)
            {
              name: "UpdateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 修改时间
            { name: "UseRuleDescription", defaultValue: this.rulesContent }, // 权益使用规则
            { name: "IsRefundAudit", defaultValue: this.auditRadio }, // IsRefundAudit 退款是否需要审核
            {
              name: "IsRealNameAuthentication",
              defaultValue: this.authRadio
            }, //  refundRadio 购买是否需要实名
            { name: "IsConfirm", defaultValue: this.refundRadio }, //  商家二次确认
            { name: "UserCount", defaultValue: this.inputValue.usersCount }, //人数
            { name: "IsRefund", defaultValue: this.inputValue.radio },
            { name: "EquityCount", defaultValue: this.inputValue.inventory } // EquityCount
          ]
        },
        data => {
          if (data.status.code == 200) {
            o.api_1322(data, Status);
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
      this.drawer = false;
    },
    // 改变公司事件
    changeCompny(item = null) {
      this.inputValue.compnySelect = this.compnySelect.value;
      this.inputValue.typeSelect = this.typeSelect.value = "";
      this.inputValue.productsSelect = this.productsSelect.value = "";
      this.inputValuecontractSelect = this.contractSelect.value = "";
      this.inputValue.title = "";
      this.$forceUpdate();

      let o = this;
      let CompanyID = item
        ? item.CompanyID
        : this.octopus.passport.authorization.company == 1
          ? this.compnySelect.value
          : o.compnySelect.options[0].ID;
      // 获取产品类型
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 198,
          cellData: [
            { name: "ID" }, // 产品标签ID
            { name: "Name" } // 产品标签中文
          ],
          paramData: {
            CompanyID: CompanyID
          },
          pageData: {
            rowSize: 777
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.typeSelect.options = data.content.queryData; //产品类型

            if (item) {
              o.typeSelect.value = o.typeSelect.options.find(
                x => x.ID == item.ProductFlagList
              ).ID;
              o.changeType(item);
            }
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 改变产品类型
    changeType(item = null) {
      let o = this;
      this.inputValue.typeSelect = this.typeSelect.value;
      this.productsSelect.value = "";
      this.contractSelect.value = "";
      let CompanyID = item
        ? item.CompanyID
        : this.octopus.passport.authorization.company == 1
          ? this.compnySelect.value
          : o.compnySelect.options[0].ID;
      // 获取产品名称
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1192,
          cellData: [
            { name: "ID" }, // ID
            { name: "Name" } // Name
          ],
          pageData: {
            rowSize: 777
          },
          paramData: {
            CompanyID: CompanyID,
            ID: this.typeSelect.value
          }
        },
        function (data) {
          if (data.status.code == 200) {
            o.productsSelect.options = data.content.queryData;

            if (item) {
              o.inputValue.productsSelect = o.productsSelect.value =
                o.productsSelect.options.length > 0
                  ? o.productsSelect.options.find(x => x.ID == item.ProductID)
                    .ID
                  : "";
              o.changeName(item);
            }
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 选择产品名称
    changeName(item = null) {
      this.inputValue.productsSelect = this.productsSelect.value;
      this.contractSelect.value = "";
      let o = this;
      // 获取合同编号
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1193,
          cellData: [
            { name: "ID" }, // ID
            { name: "Code" }, // Name
            { name: "PlatformServiceRate" }, // 平台服务费
            { name: "EquityServiceRate" }, // 小程序服务费
            { name: "CostPrice" }, // 平台价格
            { name: "SalePrice" } // 市场价格
          ],
          pageData: {
            rowSize: 777
          },
          paramData: {
            ID: this.productsSelect.value
          }
        },
        function (data) {
          if (data.status.code == 200 && data.content.queryData.length > 0) {
            o.contractSelect.options = data.content.queryData; //合同编号
            const title = o.productsSelect.options.find(
              item => item.ID == o.productsSelect.value
            );
            o.inputValue.title = title ? title.Name : o.inputValue.title;
            if (!o.is_charge) {
              o.inputValue.marketPrice = data.content.queryData[0].SalePrice;
              o.inputValue.platformPrice = data.content.queryData[0].CostPrice;
            }
            o.is_charge = false;
            o.inputValue.platformServiceCharge =
              data.content.queryData[0].PlatformServiceRate;
            o.inputValue.APPServiceCharge =
              data.content.queryData[0].EquityServiceRate;

            if (item) {
              o.inputValue.contractSelect = o.contractSelect.value = o.contractSelect.options.find(
                x => x.ID == item.ContractID
              ).ID;
            }
            if(o.title){
              o.inputValue.title = o.title;
            }
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    changeContract() {
      this.inputValue.contractSelect = this.contractSelect.value;
      this.getDeatil();
    },
    // 点击添加规则
    addRule() {
      const newId = this.refundTypeArr.length + 1;
      // 创建一个与数组中第一个对象相同结构的新对象
      const newRefundType = {
        id: newId,
        skyNumber: "",
        proportion: ""
      };
      // 将新对象添加到数组中
      this.refundTypeArr.push(newRefundType);
    },
    deleteRefund(index) {
      this.refundTypeArr.splice(index, 1);
    },
    async drawerOp(data = null, type = "CREATE") {
      this.type = type;
      this.drawer = true;
      // this.$forceUpdate();
      if (this.octopus.passport.authorization.company == 1) {
        this.inputValue.compnySelect = this.compnySelect.value = "";
      }
      if (!data) {
        for (let [k, v] of Object.entries(this.inputValue)) {
          if (k != "compnySelect") {
            this.inputValue[k] = "";
          }
        }
        this.typeSelect.value = "";
        this.productsSelect.value = "";
        this.contractSelect.value = "";
        this.lableList = [];
        this.compnyList = [];
        this.time = [];
        this.masterImg = [];
        this.figuresList = [];
        return;
      }

      await this.getInfo(data.row.ID);
    },
    // 获取详情d
    async getInfo(ID) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 778,
          cellData: [
            { name: "ProjectID" },	// ProjectID
            { name: "Address" }, // 使用地址
            { name: "CollectionID" }, // 收藏ID
            { name: "ProductID" }, // ProductID
            { name: "CompanyID" }, // 权益所属公司
            { name: "ContractID" }, // 采购公司限制
            { name: "CostPrice" }, // 平台价格
            { name: "CreateTime" }, // 创建时间
            { name: "CreateUserID" }, // 创建用户
            { name: "Description" }, // 权益内容
            { name: "EffectiveTime" }, // 生效日期
            { name: "EquityServiceRate" }, // 权益服务费
            { name: "ExpireTime" }, // 过期时间
            { name: "FlagList" }, // 权益标签
            { name: "FlagListName" }, // 权益标签中文
            { name: "ID" }, // ID
            { name: "Integral" }, // 让利积分
            { name: "InventoryID" }, // InventoryID
            { name: "InventoryQuantity" }, // 库存数量
            { name: "IsCollection" }, // 是否收藏
            { name: "IsConfirm" }, // 是否需要二次确认 ( 0不需要  1需要 ）
            { name: "IsOpenSale" }, // 是否允许在其他国企平台售卖(1.允许,0.不允许)
            { name: "IsRealNameAuthentication" }, // 是否需要实名认证信息（0 不需要  1需要）
            { name: "IsRefund" }, // 是否退款
            { name: "IsRefundAudit" }, // 退款是否需要审核
            { name: "MainPicturePath" }, // 主图
            { name: "MinimumQuantity" }, // 起售数量
            { name: "Name" }, // 权益名称/标题
            { name: "PlatformServiceRate" }, // 平台服务费
            { name: "ProductFlagList" }, // 产品标签
            { name: "ProductFlagListName" }, // 产品标签
            { name: "SalePrice" }, // 市场价格
            { name: "SecondaryPicturePath" }, // 副图
            { name: "SoldQuantity" }, // 已售数量
            { name: "Status" }, // 权益状态
            { name: "StatusName" }, // 权益状态
            { name: "TransferRuleID" }, // 采购公司限制
            { name: "TransferRuleIDName" }, // 采购公司限制 中文
            { name: "TypeID" }, // 权益类型
            { name: "UpdateTime" }, // 修改时间
            { name: "UseRuleDescription" }, // 使用规则描述
            { name: "VerifiedQuantity" }, // 权益已核销数量
            { name: "UserCount" }, // 使用人数
            { name: "PosterPath" }, // 海报图
            { name: "detailID" } // 权益详情表ID
          ],
          paramData: {
            ID: ID,
            UserID: this.octopus.passport.id
          }
        },
        res => {
          if (res.status.code == 200) {
            let item = res.content.queryData[0];
            if (item.length == 0) {
              return;
            }

            this.is_charge = true;
            this.detailID = item.detailID;
            this.inputValue.ProjectID = item.ProjectID;
            this.title = item.Name;
            this.inputValue.ID = item.ID;

            this.typeSelect.value =
              this.typeSelect.options.length > 0
                ? this.typeSelect.options.find(
                  x => x.ID == item.ProductFlagList
                ).ID
                : "";

            this.compnySelect.value = this.compnySelect.options.find(
              x => x.ID == item.CompanyID
            ).ID;

            this.changeCompny(item);
            this.inputValue.InventoryID = item.InventoryID;
            this.inputValue.time = this.time = [
              item.EffectiveTime,
              item.ExpireTime
            ];
            this.lableList = item.FlagListName.split(",");
            this.inputValue.lableListID = this.lableListID = item.FlagList;

            this.inputValue.inventory = item.InventoryQuantity;
            this.inputValue.MPnum = item.MinimumQuantity;
            this.inputValue.marketPrice = item.SalePrice;
            this.inputValue.platformPrice = item.CostPrice;
            this.inputValue.platformServiceCharge = item.PlatformServiceRate;
            this.inputValue.APPServiceCharge = item.EquityServiceRate;
            this.inputValue.Integral = item.Integral;
            this.channel = String(item.IsOpenSale);
            this.inputValue.location = item.Address;
            this.inputValue.usersCount = item.UserCount;
            this.authRadio = String(item.IsRealNameAuthentication);
            this.refundRadio = String(item.IsConfirm);
            this.inputValue.radio = String(item.IsRefund);
            this.auditRadio = String(item.IsRefundAudit);

            this.compnyListID = item.TransferRuleID;
            this.compnyList = item.TransferRuleIDName
              ? item.TransferRuleIDName.split(",")
              : [];

            // this.posterImg = item.PosterPath ? JSON.parse(item.PosterPath) : '';
            // console.log(this.posterImg);
            // this.inputValue.posterImg = item.PosterPath;

            this.masterImg =
              item.MainPicturePath.length > 0
                ? JSON.parse(item.MainPicturePath)
                : "";
            this.inputValue.masterImg = item.MainPicturePath;

            this.figuresList =
              item.SecondaryPicturePath.length > 0
                ? JSON.parse(item.SecondaryPicturePath)
                : "";
            this.inputValue.figuresList = item.SecondaryPicturePath;

            this.inputValue.deltedContent = this.deltedContent =
              item.Description;
            this.$refs.quill.content = item.Description;
            this.inputValue.rulesContent = this.rulesContent =
              item.UseRuleDescription;
            this.$refs.quillRules.content = item.UseRuleDescription;

            this.inputValue.radio > 0 && this.api_1241(ID);
          } else {
            this.octopus.tips.error(res);
          }
        }
      );
    },
    ShowLabelDialog() {
      this.$refs.LabelDialog.drawerOp(this.inputValue.lableListID);
    },
    ShowCompngDialog() {
      this.$refs.CompnyDialog.drawerOp(this.compnyListID);
    },
    getLableList(list, listID) {
      this.lableList = list;
      this.inputValue.lableListID = this.lableListID = listID;
    },
    getCompnyList(list, typeArr, scaleArr, fundArr, industryArr) {
      this.compnyListID = [
        ...typeArr,
        ...scaleArr,
        ...fundArr,
        ...industryArr
      ].join();
      console.log(list);
      this.compnyList = list;
    },
    // 添加使用权限
    addData() {
      this.dataInd++;
      this.dataList.push(this.dataInd);
    },
    // 删除使用权限
    delteData(ind) {
      this.dataList.splice(ind, 1);
      this.timeList.splice(ind, 1);
      this.time = this.timeList.join(",");
    },
    getPosterList(list) {
      this.posterImg = list;
      this.inputValue.posterImg = JSON.stringify(list);
    },
    // 获取图片信息
    getMasterList(list) {
      this.masterImg = list;
      this.inputValue.masterImg = list;
    },
    getFiguresList(list) {
      this.figuresList = list;
      this.inputValue.figuresList = list;
    },
    // 获取时间
    timeDataList(list) {
      this.inputValue.time = this.time = list;
    },

    init() {
      let o = this;
      // 公司列表
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 31,
          cellData: [
            { name: "ID" }, // 产品ID
            { name: "Name" } // 合同-产品名称
          ],
          pageData: {
            rowSize: 777
          }
        },
        function (data) {
          if (data.status.code == 200) {
            if (o.octopus.passport.authorization.company != 1) {
              let index = data.content.queryData.findIndex((item, index) => {
                return item.ID == o.octopus.passport.authorization.company;
              });
              o.compnySelect.options.push(data.content.queryData[index]);
              o.inputValue.compnySelect = o.compnySelect.value =
                o.compnySelect.options[0].Name;
              o.changeCompny();
            } else {
              o.compnySelect.options = data.content.queryData;
            }
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 权益详情
    getQuillContent(list) {
      this.inputValue.deltedContent = this.deltedContent = list;
    },
    // 使用规则
    getQuillRulesContent(list) {
      this.inputValue.rulesContent = this.rulesContent = list;
    },
    // 查找 产品信息
    getDeatil() {
      if (this.inputValue.productsSelect && this.inputValue.contractSelect) {
        this.octopus.request.api.post(
          "/Octopus/Engine/List",
          {
            id: 1248,
            cellData: [
              { name: "CompanyID" }, // 公司
              { name: "ContractID" }, // 合同ID
              { name: "CostPrice" }, // 平台价格
              { name: "Description" }, // 简介
              { name: "EquityServiceRate" }, // 小程序服务费
              { name: "ID" }, // ID
              { name: "Name" }, // 产品名称
              { name: "PlatformServiceRate" }, // 平台服务费
              { name: "ProductFlagList" }, // 产品标签
              { name: "ProductFlagListName" }, // 产品标签
              { name: "SalePrice" }, // 市场价格
              { name: "ThumbnailPath" } // 封面
            ],
            paramData: {
              ID: this.inputValue.productsSelect,
              ContractID: this.inputValue.contractSelect
            }
          },
          res => {
            if (res.status.code == 200) {
              let arr = [];
              arr = res.content.queryData[0].ThumbnailPath
                ? JSON.parse(res.content.queryData[0].ThumbnailPath)
                : [];
              this.inputValue.masterImg = this.masterImg = arr.filter(
                (v, i) => i == 0
              );
              this.inputValue.figuresList = this.figuresList = arr.filter(
                (v, i) => i != 0
              );
              this.inputValue.deltedContent = this.deltedContent =
                res.content.queryData[0].Description;
              // this.inputValue.rulesContent = this.rulesContent =res.content.queryData[0].
              this.$emit("createdSuccess", 0);
            } else {
              this.octopus.tips.error(res);
            }
          }
        );
      }
    },
    // 添加退款规则
    createRefundRules(data, refund, type = "CREATE") {
      if (this.refundType == 1) {
        refund = {
          ...refund,
          skyNumber: 0,
          proportion: 0,
          Name: "无条件退款"
        };
      } else {
        refund.skyNumber = Math.ceil(refund.skyNumber);
        refund.Name =
          "申请退款日距权益使用截止日期前" +
          Math.ceil(refund.skyNumber) +
          "小时，支持退款" +
          refund.proportion +
          "%";
        refund.TypeID = 2;
      }
      let o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1210,
          type: type,
          value: this.type == "CREATE" ? "" : refund.id,
          cellData: [
            {
              name: "CompanyID",
              defaultValue:
                o.octopus.passport.authorization.company == 1
                  ? o.compnySelect.value
                  : o.compnySelect.options[0].ID
            }, // 公司
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 创建时间
            { name: "CreateUserID", defaultValue: o.octopus.passport.id }, // 创建人
            { name: "EquityID", defaultValue: data.content.value }, // 权益
            { name: "ID" }, // ID
            { name: "InventoryID" }, // 库存
            { name: "Name", defaultValue: refund.Name }, // 规则名称
            { name: "ProductID", defaultValue: this.productsSelect.value }, // 产品ID
            {
              name: "ServiceCharge",
              defaultValue:
                refund.proportion == 0 ? 0 : (100 - refund.proportion) / 100
            }, // 服务费
            { name: "Status", defaultValue: 1 }, // 状态
            { name: "TimeLimit", defaultValue: refund.skyNumber }, // 时间限制
            { name: "TypeID", defaultValue: 2 }, // 类型ID
            { name: "UpdateTime" } // 修改时间
          ]
        },
        function (data) {
          if (data.status.code == 200) {
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    // 插入权益详情
    api_1322(data, Status) {
      let o = this;
      let cellData = [];
      if (this.type == "CREATE") {
        cellData = [
          { name: "CostPrice", defaultValue: o.inputValue.platformPrice }, // CostPrice
          {
            name: "CreateTime",
            defaultValue:
              new Date().toJSON().substring(0, 10) +
              " " +
              new Date().toTimeString().substring(0, 8)
          }, // CreateTime
          { name: "CreateUserID", defaultValue: o.octopus.passport.id }, // CreateUserID
          { name: "EquityID", defaultValue: data.content.value }, // EquityID
          { name: "MainEquityID", defaultValue: data.content.value }, // MainEquityID
          { name: "ProductID", defaultValue: o.inputValue.productsSelect }, // ProductID
          { name: "SalePrice", defaultValue: o.inputValue.marketPrice } // SalePrice
        ];
      } else {
        cellData = [
          { name: "CostPrice", defaultValue: o.inputValue.platformPrice }, // 平台家
          { name: "SalePrice", defaultValue: o.inputValue.marketPrice } // SalePrice
        ];
      }
      o.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1322,
          type: this.type,
          value: this.type == "CREATE" ? "" : this.detailID,
          cellData: cellData,
          paramData: {}
        },
        res => {
          if (res.status.code == 200) {
            if (Status == 1) {
              o.api_1186(data);
            } else {
              // if (o.inputValue.radio == "1") {
              // o.api_1196(data);
              // }
              if (o.octopus.passport.authorization.company == 1) {
                o.api_CreateEquityRecord(data);
              } else {
                o.api_1196(data);
              }
            }
          } else {
            o.octopus.tips.error(res);
          }
        }
      );
    },
    // 权益库存主表
    api_1186(data) {
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1186,
          type: this.type,
          value: this.type == "CREATE" ? "" : this.inputValue.InventoryID,
          cellData: [
            {
              name: "CompanyID",
              defaultValue:
                this.octopus.passport.authorization.company == 1
                  ? this.compnySelect.value
                  : this.octopus.passport.authorization.company
            }, // 公司ID
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 创建时间
            { name: "CreateUserID", defaultValue: this.octopus.passport.id }, // 创建人
            { name: "EquityCount", defaultValue: this.inputValue.inventory }, // 库存数量
            { name: "EquityID", defaultValue: data.content.value }, // 权益ID
            { name: "ID" }, // ID
            {
              name: "UpdateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 修改时间
            { name: "TypeID", defaultValue: 1 } // TypeID
          ]
        },
        res => {
          if (res.status.code == 200) {
            // this.createRefundRules() this.inputValue.radio == 1 && this.inputValue.refundType == 1 &&
            this.rulesFun(data);
            this.octopus.tips.success(`保存成功`);
            this.$emit("createdSuccess");
          } else {
            this.octopus.tips.error(res);
          }
        }
      );
    },
    // 获取退款规则
    api_1241(data) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1241,
          cellData: [
            { name: "CompanyID" }, // 公司ID
            { name: "CreateTime" }, // 创建时间
            { name: "CreateUserID" }, // 创建人
            { name: "EquityID" }, // 权益ID
            { name: "EquityName" }, // 权益名称
            { name: "ID" }, // ID
            { name: "InventoryID" }, // 库存
            { name: "Name" }, // 规则名称
            { name: "ProductID" }, // 产品
            { name: "ServiceCharge" }, // 手续费（%）
            { name: "Status" }, // 是否启用
            { name: "TimeLimit" }, // 时限（默认小时）
            { name: "TypeID" }, // 规则类型（1小时  2天）
            { name: "UpdateTime" } // 修改时间
          ],
          paramData: {
            EquityID: data
          }
        },
        res => {
          if (res.status.code == 200) {
            let arr = [];
            if (res.content.queryData.length == 0) {
              return;
            }
            if (
              res.content.queryData[0].TimeLimit == 0 &&
              res.content.queryData[0].ServiceCharge == 0
            ) {
              this.refundType = "1";
            } else {
              this.refundType = "0";
            }
            res.content.queryData.map(v => {
              arr.push({
                id: v.ID,
                skyNumber: v.TypeID == 1 ? v.TimeLimit / 24 : v.TimeLimit,
                proportion: 100 - v.ServiceCharge * 100
              });
            });
            this.refundTypeArr = arr;
            this.rulesArr = JSON.parse(JSON.stringify(arr));
          } else {
            this.octopus.tips.error(res);
          }
        }
      );
    },
    // 权益审核表
    api_1196(data) {
      let o = this;
      o.octopus.request.api.post("/Octopus/Engine/Item", {
        id: 1196,
        type: "CREATE",
        cellData: [
          {
            name: "CreateTime",
            defaultValue:
              new Date().toJSON().substring(0, 10) +
              " " +
              new Date().toTimeString().substring(0, 8)
          }, // 时间
          {
            name: "CreateUserID",
            defaultValue: o.octopus.passport.id
          }, // 创建人
          { name: "EquityID", defaultValue: data.content.value }, // 权益ID
          { name: "ID" }, // ID
          { name: "Opinions", defaultValue: "新增单个权益" }, // 审核内容
          { name: "Status", defaultValue: 1 } // 审核状态
        ]
      });
      // o.refundTypeArr.map(item => o.createRefundRules(data, item));

      o.rulesFun(data);
      // o.createAuditStatus(data);
      if (o.octopus.passport.authorization.company != 1) {

        o.$message({
          message: "自有权益创建成功,请等待审核。",
          type: "success"
        });


      }
      // 获取用户组
      o.$utils.getGroupInfo(o, '超级管理员,高级管理员,业务管理员', 1).then((res) => {
        let Name = o.compnySelect.options.find(x => x.ID == o.compnySelect.value).Name;

        console.log('发送消息的用户组：', res, 'Name:', Name);
        // 发送消息 传值说明 模版ID ，消息类型 ，消息里的字段 ，创建用户ID，接收公司ID，接收群组ID
        res.length > 0 && o.$utils.sendMessageMulti(5, 6, { CompanyName: Name, EquityName: o.inputValue.title }, o.octopus.passport.id, 1, res, o)
      });


      o.$emit("createdSuccess");
    },
    // 集团直接 添加库存
    api_CreateEquityRecord(data) {
      let o = this;
      o.octopus.tools.openAPI(
        "/ESB/AIGC/CreateEquityRecord",
        {
          companyID:
            o.octopus.passport.authorization.company == 1
              ? o.compnySelect.value
              : o.compnySelect.options[0].ID, // 权益所属公司ID
          equityID: data.content.value, // 权益ID
          quantity: o.inputValue.inventory, // 单个权益数量
          createUserID: o.octopus.passport.id // 创建人
        },
        datas => {
          if (datas.status.code == 200) {
            o.createAuditStatus(data, 2);
            o.$message({
              message: "自有权益创建成功",
              type: "success"
            });

            o.$emit("createdSuccess", 0);
          } else {
            o.octopus.tips.error(datas.status.message);
          }
        }
      );
    },
    close() {
      this.drawer = false;
    },
    rulesFun(data) {
      this.rulesArr.map(v => {
        this.createRefundRules(data, v, "DELETE");
      });
      this.refundTypeArr.map(v => {
        this.createRefundRules(data, v, "CREATE");
      });
    },
    // 添加审核历史
    createAuditStatus(data, type = 1) {
      let status = null,
        o = this; // 0修改提交 1提交  2通过   3驳回  6小程序上架  7平台上架 16小程序下架  17平台下架
      o.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1196,
          type: "CREATE",
          cellData: [
            { name: "EquityID", defaultValue: data.content.value }, //权益ID
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 时间
            {
              name: "Opinions",
              defaultValue: "审核通过"
            }, // 审核内容
            { name: "Status", defaultValue: type }, // 审核状态
            { name: "CreateUserID", defaultValue: o.octopus.passport.id } //创建人
          ]
        },
        data => {
          if (data.status.code == 200) {
            o.$emit("refresh");
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    api_1415() {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1415,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
          paramData: {}
        },
        data => {
          if (data.status.code == 200) {
            this.sourceList = data.content.queryData;
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
  }
};
</script>
<style scoped>
.small {
  width: 30% !important;
}

.el-icon-delete {
  font-size: 2rem;
  margin-left: 2rem;
  color: #959191;
  cursor: pointer;
}

.el-icon-delete:hover {
  color: #f78c53;
}

.button_list {
  margin-top: 1rem;
  display: flex;
  justify-content: end;
  position: absolute;
  background-color: #ffff;
  bottom: 1rem;
  width: calc(100% - 7rem);
}

.button_list button {
  border: none;
  height: 4rem;
  width: 12rem;
  border-radius: 1rem;
  margin-left: 1rem;
  color: #ffff;
  background-color: #f78c53;
  cursor: pointer;
}

.drawer_box {
  padding: 2rem;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.drawer_t {
  display: flex;
  justify-content: space-between;
  position: absolute;
  width: 100%;
  padding: 2rem;
  top: 0;
  left: 0;
  background-color: #ffff;
  /* border-bottom: 1px solid #0000; */
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
  vertical-align: middle;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
  position: absolute;
  right: 6rem;
}

.created_content {
  height: calc(100vh - 14rem);
  /* height: 100vh; */
  margin-top: 5rem;
  font-size: 1.5rem;
  padding: 0 0.5rem;
  overflow: auto;
  box-sizing: border-box;
}

.created_content .created_content_list .title {
  font-weight: 700;
  font-size: 1.7rem;
}

.created_content .created_content_list .block_box {
  box-shadow: inset 0px 0px 4px 0px #e9e9e9;
  background: #fdfdfd;
  border-radius: 1rem;
  padding: 2rem;
  margin-bottom: 2rem;
}

.created_content .created_content_list .list_box {
  display: flex;
  width: 100%;
  justify-content: space-between;
}

.created_content .created_content_list .list_box {
  /* height: 3.5rem; */
  line-height: 4rem;
  margin-top: 2rem;
}

.created_content .created_content_list .list_box .left {
  width: 20%;
  font-size: 1.5rem;
}

.created_content .created_content_list .list_box .right {
  width: 80%;
}

.created_content .created_content_list .list_box .right .delte {
  font-size: 1.6rem;
  color: #898582;
  margin-left: 2rem;
  cursor: pointer;
}

.created_content .created_content_list .list_box .right .delte:hover {
  color: #f87338;
}

.created_content .created_content_list .list_box .right .add_content {
  height: 4.5rem;
  line-height: 4.5rem;
  border: 1px dashed #f87338;
  display: inline-block;
  padding: 0 1.5rem;
  cursor: pointer;
  border-radius: 0.5rem;
}

.created_content .created_content_list .list_box .right .add_content i {
  color: #f87338;
  font-weight: 700;
  margin-right: 0.5rem;
}

.exhibition {
  display: flex;
  justify-content: space-between;
  /* margin: 2rem 0; */
}

.exhibition_title {
  font-size: 1.6rem;
}

.exhibition_content {
  display: flex;
  flex-wrap: wrap;
  max-height: 10rem;
  height: 10rem;
  overflow: auto;
  background-color: #fff;
  border: 1px solid #dcdfe6;
  width: 100%;
  border-radius: 1rem;
  padding: 0.2rem;
  overflow: auto;
}

.exhibition_content div {
  display: flex;
  align-items: center;
  background-color: #fbf8f9;
  height: 3rem;
  padding: 0 0.4rem;
  margin: 0.4rem;
  color: #898582;
  font-size: 1.2rem;
  border-radius: 1rem;
}

.el-icon-warning-outline {
  font-size: 1.6rem;
  margin-left: 0.3rem;
}

>>>.right_boder .el-input__inner {
  border: 1px solid #ff0000 !important;
  /* box-shadow: inset 0 0 2px #ff0000; */
}

>>>.el-select {
  width: 100%;
  height: 4.5rem;
}

>>>.created_content .created_content_list .list_box .right .el-input {
  width: 100%;
  height: 4.5rem;
}

>>>.el-input__inner {
  cursor: pointer;
  padding-right: 35px;
  height: 100%;
}

>>>.el-input__icon {
  line-height: 3.5rem;
}

>>>.el-input__inner:focus {
  border-color: #f87338;
  outline: 0;
}

>>>.el-select .el-input.is-focus .el-input__inner {
  border-color: #f87338;
}

.el-select-dropdown__item.selected {
  color: #f87338 !important;
  font-weight: 700;
}

>>>.el-radio__input.is-checked+.el-radio__label {
  color: #f87338;
}

>>>.el-radio__input.is-checked .el-radio__inner {
  border-color: #f87338;
  background: #f87338;
}
</style>
